package com.example.treasure_back.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.treasure_back.entity.MsgEntity;
import com.example.treasure_back.mapper.PolicyMapper;
import com.example.treasure_back.model.PolicyModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/treasure/policy")
public class PolicyController {

    @Autowired
    private PolicyMapper policyMapper;

    @RequestMapping("/getAllPolicy")
    public MsgEntity getAllPolicy(@RequestParam String province){
        QueryWrapper<PolicyModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("province",province);
        List<PolicyModel> policyModels = policyMapper.selectList(queryWrapper);
        return new MsgEntity("SUCCESS","200",policyModels);
    }

    @RequestMapping("/getPolicyById/{id}")
    public MsgEntity getPolicyById(@PathVariable Integer id){
        PolicyModel policyModel = policyMapper.selectById(id);
        return new MsgEntity("SUCCESS","200",policyModel);
    }
}
